package com.courage.shardingsphere.jdbc.server.controller;

import com.courage.shardingsphere.jdbc.common.result.ResponseEntity;
import com.courage.shardingsphere.jdbc.domain.po.TEntOrder;
import com.courage.shardingsphere.jdbc.domain.po.User;
import com.courage.shardingsphere.jdbc.service.OrderService;
import com.courage.shardingsphere.jdbc.service.RedisIdGeneratorService;
import com.courage.shardingsphere.jdbc.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;
import java.util.UUID;

/**
 * @Author xingg
 * @create 2023/3/22 15:42
 */
@Api(tags = "用户接口")
@RestController
@RequestMapping("/user")
@Slf4j
public class UserController {

    @Autowired
    private UserService userService;

    @Autowired
    private RedisIdGeneratorService redisIdGeneratorService;

    @GetMapping("/queryUserList")
    @ApiOperation("queryUserList")
    public ResponseEntity queryUserList() {
        List<User> userList=userService.queryUserList();
        return ResponseEntity.successResult(userList);
    }

    @GetMapping("/save")
    @ApiOperation("save")
    public ResponseEntity save() {
        Long entId = 5L;
        for (int i = 0; i <100; i++) {
            User user = new User();
            Long uniqueId = redisIdGeneratorService.createUniqueId(String.valueOf(entId));
            user.setId(uniqueId);
            user.setName("测试"+i);
            user.setCity("城市"+i);
            user.setCreateTime(new Date());
            userService.save(user);
        }

        return ResponseEntity.successResult("成功");
    }

    public static void main(String[] args) {
        Long id=480396691782688770L;
        long a = id % 4;
        System.out.println(a);
    }
}
